//
//  YSRegistertzgrViewController.m
//  YSZC
//
//  Created by 张斌 on 16/4/12.
//  Copyright © 2016年 YueShiKeJi. All rights reserved.
//

#import "YSRegistertzgrViewController.h"
#import "YSDoViewManager.h"

#import "LoadVcManager.h"

#import "YSTextfield.h"


@interface YSRegistertzgrViewController ()<UITextFieldDelegate>
@property (weak, nonatomic) IBOutlet UIButton *tzr_btn;
@property (weak, nonatomic) IBOutlet UIButton *tzjg_btn;
@property (weak, nonatomic) IBOutlet UIButton *gerenzichan_btn;
@property (weak, nonatomic) IBOutlet UIButton *jinsannian_btn;
@property (weak, nonatomic) IBOutlet UIView *userview;
@property (weak, nonatomic) IBOutlet UIView *phoneview;
@property (weak, nonatomic) IBOutlet UIView *checkview;
@property (weak, nonatomic) IBOutlet UIView *mailview;
@property (weak, nonatomic) IBOutlet UIView *passview1;
@property (weak, nonatomic) IBOutlet UIView *passview2;
@property (weak, nonatomic) IBOutlet UIView *tipview;
@property (weak, nonatomic) IBOutlet UIButton *registerbtn;
@property (weak, nonatomic) IBOutlet UIButton *getcodebtn;
@property (weak, nonatomic) IBOutlet UIButton *protcolbtn;

@property (weak, nonatomic) IBOutlet UITextField *user_text;
@property (weak, nonatomic) IBOutlet UITextField *phone_tx;
@property (weak, nonatomic) IBOutlet YSTextfield *check_tx;
@property (weak, nonatomic) IBOutlet YSTextfield *mail_tx;
@property (weak, nonatomic) IBOutlet YSTextfield *pass_tx1;
@property (weak, nonatomic) IBOutlet YSTextfield *pass_tx2;
@end

@implementation YSRegistertzgrViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.check_tx.delegate = self;
    self.pass_tx1.delegate = self;
    self.mail_tx.delegate = self;
    self.pass_tx2.delegate = self;
    
    self.tzr_btn.selected = YES;
    
    self.title = @"投资人注册";
    
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    [self.view endEditing:YES];
}
- (void)viewDidLayoutSubviews{
    [super viewDidLayoutSubviews];

    [[YSDoViewManager sharedmanager] settoyuanWithview:@[self.userview,self.phoneview,self.checkview,self.mailview,self.passview1,self.passview2,self.registerbtn,self.getcodebtn]];
    
    
    
}

// 关闭tip
- (IBAction)closebtnclick:(id)sender {
    self.tipview.hidden = YES ;
}

// 投资人
- (IBAction)tzrbtnclick:(id)sender {
    if (self.tzjg_btn.selected) {
        self.tzjg_btn.selected = NO;
    }

    self.tzr_btn.selected = !self.tzr_btn.selected;
    
    
}
//投资机构
- (IBAction)tzjgbtnclick:(id)sender {
    
    if (self.tzr_btn.selected) {
        self.tzr_btn.selected = NO;
    }
    self.tzjg_btn.selected = !self.tzjg_btn.selected;
    
    if (self.tzjg_btn.selected) {
        [self.navigationController pushViewController:[LoadVcManager sbVCWithsbname:@"YSRegistertzjgViewController"] animated:YES];
        
    }
   

}

// 个人资产
- (IBAction)grzcbtnclick:(id)sender {
    self.gerenzichan_btn.selected = !self.gerenzichan_btn.selected;
}
// 近三年资产
- (IBAction)jinsannianbtnclick:(id)sender {
    self.jinsannian_btn.selected = !self.jinsannian_btn.selected;
}
// 协议
- (IBAction)protcolclick:(id)sender {
    self.protcolbtn.selected = !self.protcolbtn.selected;
}
// 注册
- (IBAction)registerbtnclick:(id)sender {
    
    // 提示用户,要想成为领头人，去网页
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"温馨提示" message:@"提示用户,要想成为领头人，去网页" preferredStyle:UIAlertControllerStyleAlert];
    
    UIAlertAction *action1 = [UIAlertAction actionWithTitle:@"继续" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
        
//        NSLog(@"caonima");
        //跳转到登录界面
        [self presentViewController:[LoadVcManager sbVCWithsbname:@"YSLoginViewController"] animated:YES completion:^{

            // 最好把账号和密码放到登录界面的输入框中
            
            
            
        }];
    }];

    
    [alert addAction:action1];
    
    [self presentViewController:alert animated:YES completion:^{
    }];

}

// 跟随键盘
-(void)changeViewFrame:(NSNotification *)noti{
    //1.获取 结束时候的Frame即可
    //    NSLog(@"%@",noti);
    //2.获取结束的Frame
    CGRect endRect =  [noti.userInfo[@"UIKeyboardFrameEndUserInfoKey"]CGRectValue];
    //拿 结束的Frame中的y值 跟界面的高度做减法 得到 最终 控制器的View 的y值
    CGFloat endY = endRect.origin.y-self.view.frame.size.height+120;
    
    //设置给控制器的View的Frame即可
    CGRect oldFrame=self.view.frame;
    if (endY>0) {
        endY = 0;
    }
    oldFrame.origin.y=endY;
    
    
    self.view.frame=oldFrame;
}

- (void)textFieldDidBeginEditing:(UITextField *)textField{
    if ([textField isKindOfClass:[YSTextfield class]]) {
        [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(changeViewFrame:) name:UIKeyboardWillChangeFrameNotification object:nil];
        
    }else{
        [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillChangeFrameNotification object:nil];
    }
    
}

- (void)textFieldDidEndEditing:(UITextField *)textField{
    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillChangeFrameNotification object:nil];
}

- (void)dealloc
{
    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillChangeFrameNotification object:nil];
    
}



@end
